import * as apiService from '@/services/api';

/**
 * 取得部门权限列表
 * @returns {Promise<*>}
 */
const authDepartmentGetApi = () => apiService.post(api.AUTH_DEPARTMENT_LIST);
/**
 * 获取所有部门及岗位的基本信息
 * @returns {Promise<*>}
 */
const authDepartmentAllGetApi = () => apiService.post(api.AUTH_DEPARTMENT_ALL_LIST);
/**
 * 获取用户修改人列表
 * @returns {Promise<*>}
 */
const authModifierAllGetApi = () => apiService.post(api.AUTH_MODIFIER_ALL_LIST);

/**
 * 获取当前岗位列表
 * @param sameIpCount
 * @return {Promise<*>}
 */
const authDepartmentGetByIdApi = ({ departmentId }) => apiService.post(api.AUTH_DEPARTMENT_DETAIL,
  { departmentId });

/**
 * 新建/保存部门
 */
const authDepartmentSaveApi = (params) => {
  const {
    departmentId, jobList, name, sort, remark,
  } = params;
  if (_.isUndefined(departmentId)) {
    return apiService.post(api.AUTH_DEPARTMENT_DETAIL_SAVE,
      {
        jobList, name, sort, remark,
      });
  }
  return apiService.post(api.AUTH_DEPARTMENT_DETAIL_UPDATE,
    {
      departmentId, jobList, name, sort, remark,
    });
};

/**
 * 切换部门状态
 */
const authDepartmentToggleApi = ({ departmentId, status }) => apiService.post(api.AUTH_DEPARTMENT_STATUS_TOGGLE,
  { departmentId, status });

/**
 * 新增账号
 */
const authCreateAccountApi = ({
  userId, username, password, department, remark,
}) => {
  if (_.isUndefined(userId)) {
    return apiService.post(api.AUTH_ACCOUNT_CREATE,
      {
        username, password, jobId: department[1], remark,
      });
  }
  return apiService.post(api.AUTH_ACCOUNT_UPDATE,
    {
      userId, username, password, jobId: department[1], remark,
    });
};
/**
 * 切换账号状态
 */
const authAccountToggleApi = ({ userId, status }) => apiService.post(api.AUTH_ACCOUNT_STATUS_TOGGLE,
  { userId, status });

/**
 * 取得部门成员列表
 * @param id
 * @returns {Promise<*>}
 */
const authDepartmentMemberListApi = ({ departmentId }) => apiService.post(api.AUTH_DEPARTMENT_MEMBER_LIST,
  { departmentId });

/**
 * 获取指定部门下的岗位列表
 * @param id
 * @returns {Promise<*>}
 */
const authDepartmentJobListApi = ({ departmentId }) => apiService.post(api.AUTH_DEPARTMENT_JOB_LIST,
  { departmentId });

/**
 * 切换岗位状态
 */
const authJobToggleApi = ({ jobId, status }) => apiService.post(api.AUTH_JOB_STATUS_TOGGLE,
  { jobId, status });

/**
 * 复制权限
 * @param jobId
 * @param fromId
 * @return {Promise<*>}
 */
const authCopyPermissionApi = ({ department, fromId }) => apiService.post(api.AUTH_COPY_PERMISSION,
  { jobId: department[1], fromId });

/**
 * 账户岗位管理
 * @param id
 * @param department
 * @returns {Promise<*>}
 */
const authAccountApi = ({
  page,
  limit,
  size,
  department,
  dateType,
  fromDate,
  endDate,
  username,
  modifier,
  status,
}) => apiService.post(api.AUTH_ACCOUNT_LIST,
  {
    page,
    size,
    limit,
    departmentId: department[0],
    jobId: department[1],
    dateType,
    fromDate,
    endDate,
    username,
    modifier,
    status,
  });

/**
 * 修改用户信息
 * @param id
 * @param departmentId
 * @returns {Promise<*>}
 */
const authAccountEditApi = ({
  userId,
  username,
  password,
  department,
  remark,
}) => apiService.post(api.AUTH_ACCOUNT_UPDATE,
  {
    userId,
    username,
    password,
    jobId: department && department[1] || undefined,
    remark,
  });

/**
 * 获取所有菜单列表
 * @param id
 * @returns {Promise<*>}
 */
const authPermissionMenuListGetApi = () => apiService.post(api.AUTH_PERMISSION_MENU_LIST);
/**
 * 获取所有数据权限列表列表
 * @param id
 * @returns {Promise<*>}
 */
const authDataPermissionMenuListGetApi = () => apiService.post(api.AUTH_DATA_PERMISSION_MENU_LIST);
/**
 * 获取用户权限列表
 * @param id
 * @returns {Promise<*>}
 */
const authPermissionListGetApi = ({ jobId }) => apiService.post(api.AUTH_PERMISSION_LIST,
  {
    jobId,
  });

/**
 * 保存用户权限列表
 * @param permissionList
 * @returns {Promise<*>}
 */
const authPermissionListSaveApi = ({ menuList, jobId }) => apiService.post(api.AUTH_PERMISSION_LIST_SAVE, {
  menuList, jobId,
});

/**
 * 获取用户数据权限列表
 * @param id
 * @returns {Promise<*>}
 */
const authDataPermissionListGetApi = ({ jobId }) => apiService.post(api.AUTH_DATA_PERMISSION_LIST,
  {
    jobId,
  });
/**
 * 保存用户数据权限列表
 * @param permissionList
 * @returns {Promise<*>}
 */
const authDataPermissionListSaveApi = ({ menuList, jobId }) => apiService.post(api.AUTH_DATA_PERMISSION_LIST_SAVE, {
  menuList, jobId,
});
/**
 * 获取用户的验证二维码
 * @param userId
 * @returns {Promise<*>}
 */
const authencationCodeGetApi = ({ userId }) => apiService.post(api.AUTH_DATA_ANTHENCATION_GET, {
  userId,
});
/**
 * 重置用户的验证二维码
 * @param userId
 * @returns {Promise<*>}
 */
const resetCodeApi = ({ userId }) => apiService.post(api.AUTH_DATA_ANTHENCATION_RESET, {
  userId,
});
export {
  authDepartmentGetApi,
  authDepartmentGetByIdApi,
  authDepartmentSaveApi,
  authDepartmentToggleApi,
  authCreateAccountApi,
  authDepartmentMemberListApi,
  authCopyPermissionApi,
  authAccountApi,
  authAccountEditApi,
  authPermissionListGetApi,
  authPermissionListSaveApi,
  authAccountToggleApi,
  authDepartmentAllGetApi,
  authModifierAllGetApi,
  authDepartmentJobListApi,
  authJobToggleApi,
  authPermissionMenuListGetApi,
  authDataPermissionMenuListGetApi,
  authDataPermissionListGetApi,
  authDataPermissionListSaveApi,
  authencationCodeGetApi,
  resetCodeApi,
};
